<template>
    <div class="page-100 "  style="background-color: white">
        <div class="header-title">
            <p>联系方式</p>
            <p class="edit" @click="editClick">修改</p>
        </div>
        <div style="background-color: white;height: 30%;border-bottom: 1px solid #e5e5e5;">
            <p class="left">发起人：{{username}}</p>
            <p class="left ">机构-部门：{{jigoubumen}}</p>
            <p class="left">联系电话：{{mobile}}</p>
            <p class="left">送货地址：{{addr}}{{room}}</p>
        </div>
        <div class="header-title">采购明细</div>
        <div class="mui-flex" v-for="(item,index) in dataList">
            <div class="cell5" >
                <p class="left-title"> {{item.name}}</p>

            </div>
            <div class="cell">
                <p class="right-title"> {{item.amounts}}件</p>

            </div>
        </div>
            <div class="header-title">备注</div>
            <yd-cell-item>
                <yd-textarea slot="right" style="padding-left: 0.24rem;font-size: 0.2rem" placeholder="请输入备注信息"
                             maxlength="200" v-model="remark"></yd-textarea>
            </yd-cell-item>
        <yd-button size="large" type="primary" @click.native="confrimClick"
                   style="background-color:#83d16f;color:white;margin-top: 20px">确定
        </yd-button>

    </div>
</template>

<script>
    import {voucherapply} from "../../pcof/post";
    import {userInfoData} from '../../globalVariables'
    export default {
        name: "voucherOrder",
        data() {
            return {
                username:JSON.parse(localStorage.getItem(userInfoData)).name,
                jigoubumen:'',
                addr:JSON.parse(localStorage.getItem('address')),
                mobile: JSON.parse(localStorage.getItem('phone')),
                room:JSON.parse(localStorage.getItem('room')),
                dataList:[],
                remark:'',
            }
        },
        methods:{
            editClick ()
            {
                this.$router.push({name: 'editAddress', params: {type: '2'}});//type 1 是办公用品 2是凭证请领



            },
           async confrimClick()//确定凭证请领
            {
                /**
                 * 凭证下单信息
                 *  * applierUuid 个人的id
                 * instUuid 机构的id
                 * deptUuid部门的id
                 * contactNumber 联系电话
                 * addr 地址
                 * room房间号
                 * remark 备注信息
                 * vouchers 凭证请领的数据 json{amounts 件数 description name price supplierUuid typeName uuid}
                 */
                var mobile = JSON.parse(localStorage.getItem(userInfoData)).mobile;
                var applierUuid = JSON.parse(localStorage.getItem(userInfoData)).uuid;
                console.log(applierUuid);

                var instUuid = JSON.parse(localStorage.getItem(userInfoData)).bankUuid;
                var deptUuid = JSON.parse(localStorage.getItem(userInfoData)).departmentUuid;
                var vouchers=JSON.stringify(this.dataList);
                this.$dialog.loading.open('提交中...');

                var response = await voucherapply(mobile,applierUuid,instUuid,deptUuid,this.mobile,this.addr,this.room,this.remark,vouchers);

                if (response.data.code === 200) {

                    this.$dialog.loading.close();
                    localStorage.removeItem('voucher');
                    localStorage.removeItem('room');
                    localStorage.removeItem('phone');
                    localStorage.removeItem('address');
                    this.$router.replace({name: 'homeDetail'});


                }else
                {
                    this.$dialog.loading.close();
                    this.$dialog.toast({
                        mes: response.data.msg,
                        timeout: 1500
                    });
                }


            }
        },
        created()
        {

           var jigou=JSON.parse(localStorage.getItem(userInfoData)).bankName;
           var bumen=JSON.parse(localStorage.getItem(userInfoData)).departmentName;
           if (bumen === null||bumen==='')
           {
              this.jigoubumen=jigou;
           }else
           {
               this.jigoubumen=jigou+bumen;

           }

            this.dataList= JSON.parse(localStorage.getItem('voucher'));


        }
    }
</script>

<style scoped>
    .header-title {
        color: #9a9a9a;
        font-size: 0.2rem;
        text-align: left;
        border-bottom: 1px solid #e5e5e5;
        padding-top: 0.25rem;
        padding-left: 0.5rem;
        padding-bottom: 0.15rem;
        background-color: #fafafa;

    }
    .edit {
        color: #83d16f;
        padding-right: 0.3rem;
        padding-left: 2rem;
        margin-top: -0.35rem;
        text-align: right;
        font-size: 0.25rem;
        float: right;
    }
    .left-title {
        padding-left: 20px;
        text-align: left;
        font-size: 0.25rem;
        color: #585858;
        margin-top: 20px;
        margin-bottom: 10px;

    }
    .right-title {
        text-align: left;
        font-size: 0.25rem;
        color: #585858;
        margin-top: 20px;
        margin-bottom: 10px;

    }

    .left {
        float: left;
        margin-right: 1em;
        padding-left: 20px;
        text-align: left;
        font-size: 0.25rem;
        color: #585858;
        width: 90%;
        height: 20%;
        margin-top: 10px;

    }

</style>